﻿<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Description>用于生成 Rafy 实体类的模板</Description>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
            <Title>Rafy_Entity</Title>
            <Author>HuQingfang</Author>
            <Shortcut>Rafy_Entity</Shortcut>
        </Header>
        <Snippet>
            <Declarations>
                <Literal>
                    <ID>NAMESPACE</ID>
                    <Default>Rafy</Default>
                </Literal>
                <Literal>
                    <ID>EntityName</ID>
                    <Default>EntityName</Default>
                </Literal>
                <Literal>
                    <ID>Label</ID>
                    <Default>填写：实体业务名称（同下面的 DomainName）</Default>
                </Literal>
                <Literal>
                    <ID>BaseEntity</ID>
                    <Default>My</Default>
                </Literal>
            </Declarations>
            <Code Language="csharp">
                <![CDATA[using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Security.Permissions;
using System.Text;
using Hxy;
using Rafy;
using Rafy.Domain.ORM;
using Rafy.Domain;
using Rafy.Domain.Validation;
using Rafy.MetaModel;
using Rafy.MetaModel.Attributes;
using Rafy.MetaModel.View;
using Rafy.ManagedProperty;

namespace $NAMESPACE$
{
    /// <summary>
    /// $Label$
    /// </summary>
    [RootEntity, Serializable]
    //根据是根对象，还是子对象，在上下两行中删除一行！$end$
    [ChildEntity, Serializable]
    public class $EntityName$ : $BaseEntity$Entity
    {
        #region 构造函数

        public $EntityName$() { }

        [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
        protected $EntityName$(SerializationInfo info, StreamingContext context) : base(info, context) { }

        #endregion
        
        #region 引用属性
        
        #endregion
        
        #region 子属性
        
        #endregion
        
        #region 一般属性
        
        public static readonly Property<string> NameProperty = P<$EntityName$>.Register(e => e.Name);
        public string Name
        {
            get { return this.GetProperty(NameProperty); }
            set { this.SetProperty(NameProperty, value); }
        }
        
        #endregion
        
        #region 只读属性
        
        #endregion
    }

    [Serializable]
    public class $EntityName$List : $BaseEntity$EntityList { }

    public class $EntityName$Repository : $BaseEntity$EntityRepository 
    { 
        protected $EntityName$Repository() { }
        
        #region 数据访问
        
        #endregion
    }

    internal class $EntityName$Config : $BaseEntity$EntityConfig<$EntityName$>
    {
        protected override void ConfigMeta()
        {
            Meta.MapTable().MapAllPropertiesToTable();
        }

        protected override void ConfigView()
        {
            View.DomainName("$Label$").HasDelegate($EntityName$.NameProperty);
            
            using (View.OrderProperties())
            {
                View.Property($EntityName$.NameProperty).HasLabel("名称").ShowIn(ShowInWhere.All);
            }
        }
    }
}]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>